package com.stlm2.controller;

import com.stlm2.dems.service.CommentsService;
import com.stlm2.util.codecontent.CodeContent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by zlq on 2017/8/23.
 */
@Controller
@RequestMapping("/commentsC")
public class CommentsController {
    @Resource
    public CommentsService commentsService;


    /*
   *zlq
   *首页用户评价列表
   * @param  page:页码
   * @param  commentsPropertyValue : 评论类型值(必填) 1：最新（默认），2：晒图3：好评4：差评5：中评
   * @param  goodsId:商品ID
   *
    */
    @ResponseBody
    @RequestMapping(value="/getCommentsList.json",produces="application/json;charset=UTF-8")
    public String getCommentsList(String companyCode,ModelMap model,String page,String commentsPropertyValue,String goodsId){
        String data=null;
        try {
            data=commentsService.getCommentsList( model,page,commentsPropertyValue,goodsId);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查看评论失败" ,data);
        }
        return data;
    }
    /*
*获取评论统计数据
* zlq
* @param goodsId：商品id
*
 */
    @ResponseBody
    @RequestMapping(value="/commentsSumdatas.json",produces="application/json;charset=UTF-8")
    public String commentsSumdatas(String companyCode,ModelMap modelMap,String goodsId){
        String data=null;
        try {
            data=commentsService.commentsSumdatas(modelMap, goodsId);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"获取评论统计数据失败" ,data);
        }
        return data;
    }


    /*
    *zlq
    * 添加评论
    * token：
    * datas：评论内容 json格式
    * shopOrderId：二级订单ID
     */
    @ResponseBody
    @RequestMapping(value="/addComments.json",produces="application/json;charset=UTF-8")
    public String addComments(String companyCode,ModelMap model, String token, String datas,String shopOrderId){
        String data=null;
        try {
            data=commentsService.addComments(model,token,datas,shopOrderId);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"添加评论失败" ,data);
        }
        return data;
    }

}
